﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.Physics;
using PloobsEngine.Material;
using PloobsEngine.Utils;
using PloobsEngine.Cameras;
using PloobsEngine.Draw;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PloobsEngine.SceneControl
{
    /// <summary>
    /// Culler that uses the bepu scene controll
    /// BEPU BUG FOUND !!!!!
    /// STOPPED -- soh Conserto soh na versao 0.15 do Bepu !!!!
    /// </summary>
    internal class BepuCuller : ICuller
    {
        public BepuCuller()
        {            
        }       

        #region ICuller Members

        public IEnumerable<IObject> GetNotCulledObjectsList(IWorld world, ICamera cam, MaterialType Filter)
        {           
            
            List<IObject> obj =  (world.PhysicWorld as BepuPhysicWorld).GetIObjectsInRange(world.CameraManager.ActiveCamera.BoundingFrustum,(a,b) => (b.Material != null) && (((b.Material.MaterialType & Filter) == Filter) || ((b.Material.MaterialType & Filter) == b.Material.MaterialType))  );
            /////Funcao com problema
            Drawing.Draw2dTextAt2dLocation("Objetos desenhados " + obj.Count, new Vector2(20, 20), Color.White);            
            return obj;
            //return (IEnumerable<IObject>)world.Objects.Where((p1, p2) => obj.Contains(p1));

            //List<IObject> obj = (world.PhysicWorld as BepuPhysicWorld).GetIObjectsInRange(world.CameraManager.ActiveCamera.BoundingFrustum, (a, b) => true);
            //return obj;    

            //return world.Objects.Where((p1, p2) => (p1.Material != null) && (((p1.Material.MaterialType & Filter) == Filter) || ((p1.Material.MaterialType & Filter) == p1.Material.MaterialType)) );
            
        }

        public void onObjectAdded(IObject obj)
        {
            
        }

        public void onObjectRemoved(IObject obj)
        {
            
        }

        #endregion

        #region ICuller Members
        int num;
        public int RenderedObjectThisFrame
        {
            get { return num; }
        }

        #endregion

        #region ICuller Members


        public void StartFrame(IWorld world, ICamera cam)
        {            
        }

        #endregion
    }
}
